package controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import service.GoodsService;
import vo.Commodity;
import vo.Store;

@Controller
public class DoGoodsController {
	 @Autowired(required=true)
	 GoodsService gs;
	 @RequestMapping("/insertGoods")
	 public void insertGoods(Commodity goods,HttpServletRequest request){
		int flag=0;
		flag=gs.insertGoods(goods);
		if(flag>0){
			
		}else{
			
		}
	 }
	 @RequestMapping("/updateGoods")
	 public void updateGoods(Store goods,HttpServletRequest request){
		 
	 }
	 @RequestMapping("/deleteGoods")
	 public void deleteGoods(int goodsId,HttpServletRequest request){
		 gs.deleteGoods(goodsId);
	 }
	 @RequestMapping("/queryGoods")
	 @ResponseBody
	 public String queryGoods(int id,HttpServletRequest request){
		 System.out.println(id);
		 //gs.queryGoods(id);
		 return "yes";
	 }
	 @RequestMapping("/queryAllGoods")
	 @ResponseBody
	 public List<Commodity> queryAllGoods(int store_id){
		 List<Commodity> commodities=new ArrayList<Commodity>();
		 Store store=new Store();
		 store.setId(store_id);
		 System.out.println(store.getId());
		 if(store.getId()!=null){
			 commodities=gs.queryAllGoods(store);
		 }
		 if(commodities!=null){
			 System.out.println("has datas");
			for(int i=0;i<commodities.size();i++){
				System.out.println(commodities.get(i).getCommodiryNum());
			}
			 return commodities;
		 }
		 
		 return null;
		 
	 }
	 
}
